package team.knowers.firm.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import team.knowers.firm.common.database.BaseDO;
import team.knowers.firm.dao.entity.PaymentDO;
import team.knowers.firm.dao.mapper.PaymentMapper;
import team.knowers.firm.dto.req.PagePaymentInfoReqDTO;
import team.knowers.firm.service.PaymentService;

@RequiredArgsConstructor
@Service
public class PaymentServiceImpl extends ServiceImpl<PaymentMapper, PaymentDO> implements PaymentService {
    private final PaymentMapper paymentMapper;

    @Override
    public IPage<PaymentDO> getAllPaymentsPage(PagePaymentInfoReqDTO reqDTO) {
        return paymentMapper.selectPage(reqDTO,
                Wrappers.lambdaQuery(PaymentDO.class).eq(BaseDO::getDelFlag,0)
                        .orderByDesc(BaseDO::getCreateTime));
    }

    @Override
    public IPage<PaymentDO> getPaidPaymentsPage(PagePaymentInfoReqDTO reqDTO) {
        return paymentMapper.selectPage(reqDTO,
                Wrappers.lambdaQuery(PaymentDO.class).eq(BaseDO::getDelFlag,0)
                        .eq(PaymentDO::getIsPaid,2)
                        .orderByDesc(BaseDO::getCreateTime));
    }

    @Override
    public IPage<PaymentDO> getUnpaidPaymentsPage(PagePaymentInfoReqDTO reqDTO) {
        return paymentMapper.selectPage(reqDTO,
                Wrappers.lambdaQuery(PaymentDO.class).eq(BaseDO::getDelFlag,0)
                        .eq(PaymentDO::getIsPaid,1)
                        .orderByDesc(BaseDO::getCreateTime));
    }

    @Override
    public IPage<PaymentDO> getCanceledPaymentsPage(PagePaymentInfoReqDTO reqDTO) {
        return paymentMapper.selectPage(reqDTO,
                Wrappers.lambdaQuery(PaymentDO.class).eq(BaseDO::getDelFlag,0)
                        .eq(PaymentDO::getIsPaid,3)
                        .orderByDesc(BaseDO::getCreateTime));
    }
}
